package com.visionblue.business.ship.page

import com.visionblue.business.ship.base.BaseRepository
import com.visionblue.business.ship.model.Results
import com.visionblue.business.ship.model.bean.response.ShipInfo
import com.visionblue.business.ship.model.bean.response.NotificationBean
import com.visionblue.business.ship.model.repository.RemoteRepository
import com.visionblue.business.ship.model.repository.db.RecordAndOrderDao
import com.visionblue.business.ship.model.repository.db.RecordAndOrderRelation

/**
 * @author: xlh
 * @date: 2020-05-21 2:23 PM
 * @desc:
 */
class MainRepository(private val recordAndOrderDao: RecordAndOrderDao) : BaseRepository() {

    suspend fun getHostShipInfo(): Results<ShipInfo> {
        return safeApiCall(call = { RemoteRepository.getHostShipInfo() })
    }

    suspend fun getNotification(): Results<NotificationBean> {
        return safeApiCall(call = { RemoteRepository.getTaskNotification() })
    }

//    override suspend fun getApplications(
//        page: Int,
//        size: Int,
//        status: Int
//    ): Results<ListBean<ApplicationDetail>> {
//        return safeApiCall(call = { RemoteRepository.getApplications(page, size, status) })
//    }

    suspend fun putApplicationView(id: String): Results<Any> {
        return safeApiCall(call = { RemoteRepository.putApplicationView(id) })
    }

    suspend fun putApplicationStatus(id: String, opCode: Int): Results<Any> {
        return safeApiCall(call = { RemoteRepository.putApplicationStatus(id, opCode) })
    }

    suspend fun getCachedOrders(sn: String): List<RecordAndOrderRelation> {
        return recordAndOrderDao.getAllCachedOrderWithCollectionRecords(sn)
    }
}